<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\controller\ding;

use app\api\controller\Controller;
use app\api\model\ding\ShopDish as ShopDishModel;
use cores\exception\BaseException;
use think\facade\Db;
use think\response\Json;

/**
 * 购物车管理
 * Class Cart
 * @package app\api\controller
 */
class Dish extends Controller
{
    /**
     *
     * @return Json
     * @throws BaseException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \cores\exception\BaseException
     */
    public function list(): Json
    {
        $params = $this->request->param();

        $shopId = $params['shopId'];
        $model  = new ShopDishModel;

        $list = $model->getList((int)$shopId, $params);

        return $this->renderSuccess(compact('list'));
    }

    public function add(): Json
    {
        $model  = new ShopDishModel;
        $params = $this->request->param();

        $shopId = $params['shopId'];
        $model->add($shopId, $this->postForm());
        return $this->renderSuccess([], '保存成功');
    }

    public function detail(int $seatId)
    {
        $detail = SeatModel::detail($seatId);
        return $this->renderSuccess(compact('detail'));
    }

}
